
package com.trydofor.a9task.base.code.sysd;

import com.trydofor.a9task.base.code.help.Code;
import com.trydofor.a9task.base.code.help.CodeBuilder;
import com.trydofor.a9task.base.sys.anno.SystemData;

/**
 * @author : Shi Rongjiu (www.trydofor.com)
 * @date : 2012-12-23
 * @see :
 */

public abstract class Sequence {

    public final static int    $   = GroupRoot.$SEQUENCE$;
    public final static String _   = "SEQUENCE$";
    @SystemData
    public final static Code   $_  = CodeBuilder.code(GroupRoot.$, $, _)
   	                                            .lang(Language.$EN_US, "sequence group", "almost linear sequence")
   	                                            .lang(Language.$ZH_CN, "序列组", "不严格的线性序列")
                                                .done();
    
    public final static int    $CODE_CORE  = $ + 1;
    public final static String _CODE_CORE  = "SEQUENCE$CODE_CORE";
    @SystemData
    public final static Code   CODE_CORE   = CodeBuilder.code($, $CODE_CORE, _CODE_CORE)
                                                   .lang(Language.$EN_US, "core code sequence")
                                                   .lang(Language.$ZH_CN, "核心码表序列")
                                                   .done();
    public final static int    $CODE_USER  = $ + 2;
    public final static String _CODE_USER  = "SEQUENCE$CODE_USER";
    @SystemData
    public final static Code   CODE_USER   = CodeBuilder.code($, $CODE_USER, _CODE_USER)
                                                   .lang(Language.$EN_US, "user code sequence")
                                                   .lang(Language.$ZH_CN, "用户码表序列")
                                                   .done();
    public final static int    $USER_MAIN  = $ + 3;
    public final static String _USER_MAIN  = "SEQUENCE$USER_MAIN";
    @SystemData
    public final static Code   USER_MAIN   = CodeBuilder.code($, $USER_MAIN, _USER_MAIN)
                                                   .lang(Language.$EN_US, "main user sequence")
                                                   .lang(Language.$ZH_CN, "用户主表序列")
                                                   .done();

    ///////////////////////
    /**
     * true if id is the system default data
     * @param id the code id
     * @return
     */
    public final static boolean in(int id){
        if($CODE_CORE == id) return true;
        if($CODE_USER == id) return true;
        if($USER_MAIN == id) return true;
        return false;
    }
    
    /**
     * get the code by id
     * @param id the code id
     * @return
     */
    public final static Code of(int id){
        if($CODE_CORE == id) return CODE_CORE;
        if($CODE_USER == id) return CODE_USER;
        if($USER_MAIN == id) return USER_MAIN;
        return null;
    }
    
    /**
     * get the code by key
     * @param id the code key
     * @return
     */
    public final static Code of(String key){
        if(key == null) return null;
        if(_CODE_CORE.equals(key)) return CODE_CORE;
        if(_CODE_USER.equals(key)) return CODE_USER;
        if(_USER_MAIN.equals(key)) return USER_MAIN;
        return null;
    }
}
